/**
 * @Description:
 * @Author bianpengfei
 * @create 2022/11/24 18:55
 */
import dayjs from 'dayjs'
import { isPlainObject, requireAllModule } from 'sf-utils2'
import { basename } from 'path'
import xss from 'xss'

const modules = requireAllModule({
  requireContext: require.context('./modules', true, /\.js$/),
  exclude: ['./modules/index.js']
}).reduce((pre, [v, k]) => {
  if (isPlainObject(v?.default)) {
    const name = basename(k, '.js')
    pre[name] = v.default
    return { ...pre, [name]: v.default }
  }
  return pre
}, {})

export default {
  install(app) {
    app.config.globalProperties.$xss = xss
    // app.use(VueGridLayout)
    app.config.globalProperties.$dayjs = dayjs
    app.config.globalProperties.$console = window.console
    Object.values(modules).forEach((v) => {
      app.use(v)
    })
  }
}
